#include <QStringList>
#include "ClassifierPassport.h"

ClassifierPassport::ClassifierPassport(const QString &name)
    : _name(name), _description(QString::null), _fields()
{

}

ClassifierPassport::ClassifierPassport(const QString &name, const QString &description)
    : _name(name), _description(description), _fields()
{

}

ClassifierPassport::~ClassifierPassport()
{
    _fields.clear();
}

QString ClassifierPassport::getName() const
{
    return _name;
}

void ClassifierPassport::setName(const QString &name)
{
    _name = name;
}

QString ClassifierPassport::getDescription() const
{
    return _description;
}

void ClassifierPassport::setDescription(const QString &desc)
{
    _description = desc;
}

QList<BaseField> ClassifierPassport::fields() const
{
    return _fields.values();
}

QList<QString> ClassifierPassport::fieldNames() const
{
    return _fields.keys();
}

BaseField & ClassifierPassport::operator[](const QString &name)
{
    return _fields[name];
}

BaseField & ClassifierPassport::operator[](int index)
{
    return _fields[_fields.keys()[index]];
}

BaseField & ClassifierPassport::getField(const QString &name)
{
    return _fields[name];
}

BaseField & ClassifierPassport::getFieldAt(int index)
{
    return _fields[_fields.keys()[index]];
}


void ClassifierPassport::addField(const BaseField &field)
{
    _fields.insert(field.getName(), field);
}

void ClassifierPassport::addField(const QList<BaseField> &fields)
{
    for(int i = 0; i < fields.count(); ++i)
        _fields.insert(fields[i].getName(), fields[i]);
}

void ClassifierPassport::removeField(const QString &name)
{
    _fields.remove(name);
}

QString ClassifierPassport::toString()
{
    QString str = "Passport \"" + _name + "\" :";
    QStringList list;

    for(int i = 0; i < _fields.count(); ++i)
        list << _fields.values()[i].toString();

    return str + list.join(", ");
}
